package com.thor.palmmall.rest.process;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.thor.commons.exception.ThorServiceException;
import com.thor.palmmall.rest.process.converter.AProcessAttentionsConverter;
import com.thor.palmmall.rest.process.converter.SProcessConverter;
import com.thor.palmmall.rest.process.converter.SProcessParamConverter;
import com.thor.palmmall.spi.common.SResponse;
import com.thor.palmmall.spi.process.SProcessAttentions;
import com.thor.palmmall.spi.process.SProcessService;

public class AProcessServiceImpl implements AProcessService {
  @Autowired
  private SProcessService sProcessService ;
  
  @Override
  public List<String> getAllProcesses(AProcessParam processParam) throws ThorServiceException {
    SResponse<List<String>> resp = sProcessService.allStartProcesses(SProcessParamConverter.getInstance().convert(processParam));
    if (resp.isSuccess()){
         return resp.getBody();
    }  else{
         throw new ThorServiceException("无法查询到流程：" + resp.getMessage());
    }
  }

  @Override
  public void saveUserAttentionProcess(AProcess process) throws ThorServiceException {
    SResponse<Void> resp = sProcessService.saveUserAttentionProcess(SProcessConverter.getInstance().convert(process));
    if (resp.isSuccess() == false){
      throw new ThorServiceException("无法保存关注流程：" + resp.getMessage());
    }
  }

  @Override
  public AProcessAttentions getAllAttentionProcess(String userId) throws ThorServiceException {
    SResponse<SProcessAttentions> resp = sProcessService.getAllAttentionProcess(userId);
    if (resp.isSuccess()){
        return AProcessAttentionsConverter.getInstance().convert(resp.getBody());
    }else{
        throw new ThorServiceException("无法创建投诉单：" + resp.getMessage());
    }

  }

}
